<?php
/**
 * usermonitorsitedefine.php
 * Create on 2015-05-28
 * Create by yuebin
 */
namespace haibao\cms\business\behavior;

use \haibao\cms\data\behavior\UserMonitorSiteDefine as UserMonitorSiteDefineData;
use \haibao\cms\business\BusinessException;

class UserMonitorSiteDefine extends \haibao\cms\business\Base{
	
	public static function getInfoByFilter($filter){
		
		$data = new UserMonitorSiteDefineData;
		return $data->getAll($filter);
		
	}
	public static function addUserMonitorSiteDefine($model){
		self::checkOperation(self::FUNC_CODE_USER_MONITOR_SITE_DEFINE_ADD);
		
		if(!isset($model->SiteDomain)){
			throw new BusinessException('站点域名不能为空',self::DATA_EMPTY);
		}
		if(!isset($model->SiteName)){
			throw new BusinessException('站点名称不能为空',self::DATA_EMPTY);
		}
		
		$model->Status = \haibao\cms\model\data\behavior\UserMonitorSiteDefine::STATUS_ENABLE;
		$data = new UserMonitorSiteDefineData();
		$data->add($model);
		
		self::saveOperateHistory(self::FUNC_CODE_USER_MONITOR_SITE_DEFINE_ADD, $model->toArray(false));
	}
	
	public static function updateUserMonitorSiteDefine($id,$arrSet){
		
		self::checkOperation(self::FUNC_CODE_USER_MONITOR_SITE_DEFINE_EDIT);	
	
		if(!isset($arrSet['SiteDomain'])){
			throw new BusinessException('站点域名不能为空',self::DATA_EMPTY);
		}
		if(!isset($arrSet['SiteName'])){
			throw new BusinessException('站点名称不能为空',self::DATA_EMPTY);
		}
		$data = new UserMonitorSiteDefineData();
		$data->updateById($id, $arrSet);
		
		self::saveOperateHistory(self::FUNC_CODE_USER_MONITOR_SITE_DEFINE_EDIT, $arrSet);
	}
	
	public static function getModelById($id){
		if(!$id){
			return NULL;
		}
		$data = new UserMonitorSiteDefineData();
		return $data->getOneById($id);
	}
	
	public static function getUserMonitorSiteList($filter){
		$data = new UserMonitorSiteDefineData();
		return $data->getAll($filter);
	}
	
	
	/**
	 * 修改状态
	 * @param int $id
	 * @param int $status
	 */
	public static function changUserMonitorSiteStatus($id,$status){
		if (!$id){
			throw new BusinessException('id不能为空',self::DATA_EMPTY_ID);
		}

		$data = new UserMonitorSiteDefineData();
		$data->updateById($id, array(\haibao\cms\model\filter\behavior\UserMonitorSiteDefine::CONDITION_FIELD_NAME_STATUS=>(int)$status));
	
		self::saveOperateHistory(self::FUNC_CODE_USER_MONITOR_SITE_DEFINE_EDIT, array('id'=>$id,'status'=>$status));
	}
}
